home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / lang / ApplicationShutdownHooks.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  1.7 KB  |  63 lines

  1. package java.lang;
  2.  
  3. import java.util.IdentityHashMap;
  4. import java.util.Set;
  5.  
  6. class ApplicationShutdownHooks implements Runnable {
  7.    private static ApplicationShutdownHooks instance = null;
  8.    private static IdentityHashMap<Thread, Thread> hooks = new IdentityHashMap();
  9.  
  10.    static synchronized ApplicationShutdownHooks hook() {
  11.       if (instance == null) {
  12.          instance = new ApplicationShutdownHooks();
  13.       }
  14.  
  15.       return instance;
  16.    }
  17.  
  18.    private void ApplicationShutdownHooks() {
  19.    }
  20.  
  21.    static synchronized void add(Thread var0) {
  22.       if (hooks == null) {
  23.          throw new IllegalStateException("Shutdown in progress");
  24.       } else if (var0.isAlive()) {
  25.          throw new IllegalArgumentException("Hook already running");
  26.       } else if (hooks.containsKey(var0)) {
  27.          throw new IllegalArgumentException("Hook previously registered");
  28.       } else {
  29.          hooks.put(var0, var0);
  30.       }
  31.    }
  32.  
  33.    static synchronized boolean remove(Thread var0) {
  34.       if (hooks == null) {
  35.          throw new IllegalStateException("Shutdown in progress");
  36.       } else if (var0 == null) {
  37.          throw new NullPointerException();
  38.       } else {
  39.          return hooks.remove(var0) != null;
  40.       }
  41.    }
  42.  
  43.    public void run() {
  44.       Set var1;
  45.       synchronized(ApplicationShutdownHooks.class) {
  46.          var1 = hooks.keySet();
  47.          hooks = null;
  48.       }
  49.  
  50.       for(Thread var3 : var1) {
  51.          var3.start();
  52.       }
  53.  
  54.       for(Thread var9 : var1) {
  55.          try {
  56.             var9.join();
  57.          } catch (InterruptedException var5) {
  58.          }
  59.       }
  60.  
  61.    }
  62. }
  63.